<?php

defined('BASEPATH') or die('forbidden');

class Vipvendor_Controller Extends Controller {

	private $rolename;
	private $inc;
	private $dbConnt;	//数据库连接
	private $objectlist;	//物品名字
	
	function _init() {//print_r($_SESSION['tttttkk']);
		check_level(50, segment(0), segment(1));

		$this->inc = $this->config['inc'];
		
		//得到选择的区号
		$areanum = $_SESSION['area_selected_id'];
        if ($areanum == '') 
        {
            echo "<script>alert('" . translate('C_SELECT_AREA_TEXT') . "');</script>";
            return;
        }
        // db数据库
		$this->dbConnt = getTmpDbConnect(PLATFORM_ALL, 'all', $areanum, DBTYPE_GAMESERVER);
		
		if (false == $this->dbConnt) {
			//内部有提示错误，在此就不提示了
			 //echo "<script>alert(' connect areanum:$areanum error ');</script>";
            return;
		}	
		
		$this->objectlist = get_type_object_db();
	}

	function index() {
		$this->view->display("dbvip/vipvendor/index");
	}

	function flexigrid() {
			
		list($colkey, $colsinfo, $where, $sortname, $sortorder, $offset, $rp, $page) = $this->common->get_flexigrid_params();
			
		//$this->db->connect('111.75.194.177','root','654321');
		//200090016 表示 充值	
		$sql = "SELECT COUNT(*) AS num FROM player_vip_vendor  where {$where} ";
		//echo " sql2:$sql ";
		$one = $this->dbConnt->one($sql);
		$total = $one['num'];
		$orderby = $sortname ? "ORDER BY {$sortname} {$sortorder} " : "";
			
		$sql = "SELECT {$colsinfo} FROM player_vip_vendor   where {$where}  {$orderby} LIMIT {$offset},{$rp}";
		$this->dbConnt->query($sql);
		//$id = 0;
		while ($n = $this->dbConnt->get_array('default'))
		{
			//print_r($n);
			//时间需要由数字转成字符串
			$n['objectid']=$this->objectlist[$n['objectid']]."-(".$n['objectid'].")";
			$rows[] = array('id' => $n['id'], 'cell' => $n);
			//$id = $id+1;
		}
		//var_dump($rows);
		$result = array(
	            'page' => $page,
	            'total' => $total,
	            'rows' => $rows
		);
			
		echo json_encode($result);
	}

}

?>